package com.ww.microrpc.netty.handler.server;

import com.ww.microrpc.netty.protocol.ResponseMessage;
import com.ww.microrpc.netty.protocol.ErrorMessage;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * RPC Handler（RPC request processor）
 *
 * @author ww
 */
public class ErrorMessageHandler extends SimpleChannelInboundHandler<ErrorMessage> {

    private static final Logger logger = LoggerFactory.getLogger(ErrorMessageHandler.class);

    @Override
    public void channelRead0(final ChannelHandlerContext ctx, final ErrorMessage errorMessage) {
        ResponseMessage response = new ResponseMessage();
        response.setRequestId(errorMessage.getRequestId());
        response.setErrorMessage(errorMessage.getErrorMessage());
        ctx.writeAndFlush(response);
    }
}
